package com.xm.ojbackendjudge.judge;

import com.xm.ojbackendjudge.judge.strategy.DefaultJudgeStrategy;
import com.xm.ojbackendjudge.judge.strategy.JavaJudgeStrategy;
import com.xm.ojbackendjudge.judge.strategy.JudgeContext;
import com.xm.ojbackendjudge.judge.strategy.JudgeStrategy;
import com.xm.ojbackendmodel.model.codesandbox.JudgeInfo;
import com.xm.ojbackendmodel.model.entity.QuestionSubmit;
import org.springframework.stereotype.Service;

/**
 * 策略管理类
 *
 * 简化实现时的代码
 */

@Service
public class JudgeManager {

    /**
     * 执行判题
     * @param judgeContext
     * @return
     */
    JudgeInfo doJudge(JudgeContext judgeContext) {
        JudgeStrategy judgeStrategy = new DefaultJudgeStrategy();
        QuestionSubmit questionSubmit = judgeContext.getQuestionSubmit();
        String language = questionSubmit.getLanguage();
        if ("java".equals(language)) {
            judgeStrategy = new JavaJudgeStrategy();
        }
        return judgeStrategy.doJudge(judgeContext);
    }
}
